* File names and labels variables of data set "decision_dynamics.cvs"
* File generates new variables for analyses

clear

set mem 500m

use "decision_dynamics.dta"

set more off
set more off, permanently


*******************************************************************
***	Definitions of labels used in dataset
*******************************************************************


label define lb_sessionid 1 "11.07.2016, 12:00"
label define lb_sessionid 2 "11.07.2016, 14:00", add
label define lb_sessionid 3 "11.07.2016, 16:00", add
label define lb_sessionid 4 "13.07.2016, 14:00", add
label define lb_sessionid 5 "11.07.2016, 16:00", add
label define lb_sessionid 6 "06.10.2016, 10:00", add

label define lb_treatment 1 "Treatment 1"
label define lb_treatment 2 "Treatment 2", add
label define lb_treatment 3 "Treatment 3", add

label define lb_type 1 "Player A"
label define lb_type 2 "Player B", add
label define lb_type 3 "Player C", add
label define lb_type 4 "Player D", add
label define lb_type 5 "Player E", add

label define lb_yes_no 1 "yes"
label define lb_yes_no 0 "no", add

label define lb_noanswer -99 "no answer"

label define lb_yes_no_noanswer 0 "no"
label define lb_yes_no_noanswer 1 "yes", add
label define lb_yes_no_noanswer -99 "no answer", add

label define lb_proposer_dec 0 "Proposal to adjourn"
label define lb_proposer_dec 1 "Proposal new point", add
label define lb_proposer_dec 2 "Agendasetter timed out", add

label define lb_decision 1 "Status quo maintained"
label define lb_decision 2 "Proposed new point accepted", add
label define lb_decision 3 "Continue decision making", add
label define lb_decision 4 "Adjourn decision making", add
label define lb_decision 5 "Agendasetter timed out", add

label define lb_prop -99 "Agendasetter made no proposal"

label define lb_adj -99 "Agendasetter did not propose to adjourn"

label define lb_final -99 "No final decision reached so far in period"

label define lb_vote_prop 0 "No"
label define lb_vote_prop 1 "Yes", add
label define lb_vote_prop -99 "Agendasetter made no proposal", add

label define lb_vote_adj 0 "No"
label define lb_vote_adj 1 "Yes", add
label define lb_vote_adj -99 "Agendasetter did not propose to adjourn", add

label define lb_final_yes_no 0 "No"
label define lb_final_yes_no 1 "Yes", add
label define lb_final_yes_no -99 "No final decision reached so far in period", add

label define lb_prop_yes_no 0 "No"
label define lb_prop_yes_no 1 "Yes", add
label define lb_prop_yes_no -99 "Agendasetter made no proposal", add




*******************************************************************
***	Naming and labeling of variables in dataset
*** Generation of new variables for analyses
*******************************************************************


* sessionid
label variable sessionid "Session ID"
label values sessionid lb_sessionid
notes sessionid : Date and starting time of session

*treatment
label variable treatment "Treatment"
label values treatment lb_treatment

*period
label variable period "Period"

*group
label variable group "Group ID in treatment"

*groupid
label variable groupid "Group ID"
notes groupid: Treatment_Group

*decisionid1
label variable decisionid1 "Decision ID 1"
notes decisionid1: Treatment_Period_Group_Num_AG

*decisionid2
label variable decisionid2 "Decision ID 2"
notes decisionid2: Treatment_Group_Num_AG_Period

*decisionid3
label variable decisionid3 "Decision ID 3"
notes decisionid3: Treatment_Group_Period_Num_AG

*num_ag
label variable num_ag "Number of current decision step"
notes num_ag: Variable shows the number of agenda setters in period.

*agendasetter
label variable agendasetter "Agendasetter"
label values agendasetter lb_type

*proposer_dec
label variable proposer_dec "Decision of agendasetter"
label values proposer_dec lb_proposer_dec

* decision
label variable decision "Outcome of current decision step"
label values decision lb_decision

* sq_x
label variable sq_x "x-coordinate of current status quo"

* sq_y
label variable sq_y "y-coordinate of current status quo"

* prop_x
label variable prop_x "x-ccordinate of agendasetter's proposal"
label values prop_x lb_prop

* prop_y
label variable prop_y "y-ccordinate of agendasetter's proposal"
label values prop_y lb_prop

*final_x
label variable final_x "x-coordinate of selected point in period"
label values final_x lb_final

*final_y
label variable final_y "y-coordinate of selected point in period"
label values final_y lb_final

*sum_alt
label variable sum_alt "Number of group members voting for proposal"
label values sum_alt lb_prop

*sum_sq
label variable sum_sq "Number of group members voting for status quo"
label values sum_sq lb_prop

*sum_adj
label variable sum_adj "Number of group members voting 'adjourn'"
label values sum_adj lb_adj

*sum_cont
label variable sum_cont "Number of group members voting 'continue'"
label values sum_cont lb_adj

*points_a
label variable points_a "Number of points for Player A for coordinates of proposal"
label values points_a lb_prop

*points_b
label variable points_b "Number of points for Player B for coordinates of proposal"
label values points_b lb_prop

*points_c
label variable points_c "Number of points for Player C for coordinates of proposal"
label values points_c lb_prop

*points_d
label variable points_d "Number of points for Player D for coordinates of proposal"
label values points_d lb_prop

*points_e
label variable points_e "Number of points for Player E for coordinates of proposal"
label values points_e lb_prop

* points_avg
generate points_avg = (points_a + points_b + points_c + points_d + points_e)/5
replace points_avg = -99 if proposer_dec!=1
label variable points_avg "Average number of points for committee for coordinates of proposal"
label values points_avg lb_prop

* points_sd
generate points_sd = (((points_a - points_avg)^2 + (points_b - points_avg)^2 + (points_c - points_avg)^2 + (points_d - points_avg)^2 + (points_e - points_avg)^2)/5)^0.5
replace points_sd = -99 if proposer_dec!=1
label variable points_sd "Standard deviation of points for coordinates of proposal"
label values points_avg lb_prop

*sq_points_a
label variable sq_points_a "Number of points for Player A for coordinates of status quo"

*sq_points_b
label variable sq_points_b "Number of points for Player B for coordinates of status quo"

*sq_points_c
label variable sq_points_c "Number of points for Player C for coordinates of status quo"

*sq_points_d
label variable sq_points_d "Number of points for Player D for coordinates of status quo"

*sq_points_e
label variable sq_points_e "Number of points for Player E for coordinates of status quo"

* sq_points_avg
generate sq_points_avg = (sq_points_a + sq_points_b + sq_points_c + sq_points_d + sq_points_e)/5
label variable sq_points_avg "Average number of points for committee for coordinates of status quo"

* sq_points_sd
generate sq_points_sd = (((sq_points_a - sq_points_avg)^2 + (sq_points_b - sq_points_avg)^2 + (sq_points_c - sq_points_avg)^2 + (sq_points_d - sq_points_avg)^2 + (sq_points_e - sq_points_avg)^2)/5)^0.5
label variable sq_points_sd "Standard deviation of points for coordinates of status quo"


*vote_a_sq
label variable vote_a_sq "Did Player A vote for status quo?"
label values vote_a_sq lb_vote_prop

*vote_b_sq
label variable vote_b_sq "Did Player B vote for status quo?"
label values vote_b_sq lb_vote_prop

*vote_c_sq
label variable vote_c_sq "Did Player C vote for status quo?"
label values vote_c_sq lb_vote_prop

*vote_d_sq
label variable vote_d_sq "Did Player D vote for status quo?"
label values vote_d_sq lb_vote_prop

*vote_e_sq
label variable vote_e_sq "Did Player E vote for status quo?"
label values vote_e_sq lb_vote_prop

*vote_a_alt
label variable vote_a_alt "Did Player A vote for proposal?"
label values vote_a_alt lb_vote_prop

*vote_b_alt
label variable vote_b_alt "Did Player B vote for proposal?"
label values vote_b_alt lb_vote_prop

*vote_c_alt
label variable vote_c_alt "Did Player C vote for proposal?"
label values vote_c_alt lb_vote_prop

*vote_d_alt
label variable vote_d_alt "Did Player D vote for proposal?"
label values vote_d_alt lb_vote_prop

*vote_e_alt
label variable vote_e_alt "Did Player E vote for proposal?"
label values vote_e_alt lb_vote_prop

*vote_a_adj
label variable vote_a_adj "Did Player A vote to adjourn?"
label values vote_a_adj lb_vote_adj

*vote_b_adj
label variable vote_b_adj "Did Player B vote to adjourn?"
label values vote_b_adj lb_vote_adj

*vote_c_adj
label variable vote_c_adj "Did Player C vote to adjourn?"
label values vote_c_adj lb_vote_adj

*vote_d_adj
label variable vote_d_adj "Did Player D vote to adjourn?"
label values vote_d_adj lb_vote_adj

*vote_e_adj
label variable vote_e_adj "Did Player E vote to adjourn?"
label values vote_e_adj lb_vote_adj

*vote_a_cont
label variable vote_a_cont "Did Player A vote to adjourn?"
label values vote_a_cont lb_vote_adj

*vote_b_cont
label variable vote_b_cont "Did Player B vote to adjourn?"
label values vote_b_cont lb_vote_adj

*vote_c_cont
label variable vote_c_cont "Did Player C vote to adjourn?"
label values vote_c_cont lb_vote_adj

*vote_d_cont
label variable vote_d_cont "Did Player D vote to adjourn?"
label values vote_d_cont lb_vote_adj

*vote_e_cont
label variable vote_e_cont "Did Player E vote to adjourn?"
label values vote_e_cont lb_vote_adj

* time_in_stage2
label variable time_in_stage2 "Total duration of decision in period until end of current decision step"

* time_for_decision_step
label variable time_for_decision_step "Duration of decision step"

*final_ucset
generate final_ucset = -99
label variable final_ucset "Final result in uncovered set"
label values final_ucset lb_final_yes_no
replace final_ucset = 0 if final_x>=0 & final_y>=0
replace final_ucset = 1 ///
	if ///
	(final_y == 51 & final_x == 49) | ///
	(final_y == 50 & final_x >= 44 & final_x<=54) | ///
	(final_y == 49 & final_x >= 39 & final_x<=59.5) | ///
	(final_y == 48 & final_x >= 37.5 & final_x<=60.3) | ///
	(final_y == 47 & final_x >= 37.5 & final_x<=60.8) | ///
	(final_y == 46 & final_x >= 37.5 & final_x<=60.8) | ///
	(final_y == 45 & final_x >= 37.5 & final_x<=60.8) | ///
	(final_y == 44 & final_x >= 37.5 & final_x<=60.2) | ///
	(final_y == 43 & final_x >= 38 & final_x<=60.8) | ///
	(final_y == 42 & final_x >= 38 & final_x<=60.8) | ///
	(final_y == 41 & final_x >= 38 & final_x<=60.8) | ///
	(final_y == 40 & final_x >= 38 & final_x<=59.8) | ///
	(final_y == 39 & final_x >= 39 & final_x<=59.3) | ///
	(final_y == 38 & final_x >= 39 & final_x<=59.3) | ///
	(final_y == 37 & final_x >= 40 & final_x<=58.3) | ///
	(final_y == 36 & final_x >= 41 & final_x<=56.8) | ///
	(final_y == 35 & final_x >= 42 & final_x<=55)
	
*sq_ucset
generate sq_ucset = -99
label variable sq_ucset "Status quo in uncovered set"
label values sq_ucset lb_yes_no
replace sq_ucset = 0 if sq_x>=0 & sq_y>=0
replace sq_ucset = 1 ///
	if ///
	(sq_y == 51 & sq_x == 49) | ///
	(sq_y == 50 & sq_x >= 44 & sq_x<=54) | ///
	(sq_y == 49 & sq_x >= 39 & sq_x<=59.5) | ///
	(sq_y == 48 & sq_x >= 37.5 & sq_x<=60.3) | ///
	(sq_y == 47 & sq_x >= 37.5 & sq_x<=60.8) | ///
	(sq_y == 46 & sq_x >= 37.5 & sq_x<=60.8) | ///
	(sq_y == 45 & sq_x >= 37.5 & sq_x<=60.8) | ///
	(sq_y == 44 & sq_x >= 37.5 & sq_x<=60.2) | ///
	(sq_y == 43 & sq_x >= 38 & sq_x<=60.8) | ///
	(sq_y == 42 & sq_x >= 38 & sq_x<=60.8) | ///
	(sq_y == 41 & sq_x >= 38 & sq_x<=60.8) | ///
	(sq_y == 40 & sq_x >= 38 & sq_x<=59.8) | ///
	(sq_y == 39 & sq_x >= 39 & sq_x<=59.3) | ///
	(sq_y == 38 & sq_x >= 39 & sq_x<=59.3) | ///
	(sq_y == 37 & sq_x >= 40 & sq_x<=58.3) | ///
	(sq_y == 36 & sq_x >= 41 & sq_x<=56.8) | ///
	(sq_y == 35 & sq_x >= 42 & sq_x<=55)
	
*prop_ucset
generate prop_ucset = -99
label variable prop_ucset "Proposal in uncovered set"
label values prop_ucset lb_prop_yes_no
replace prop_ucset = 0 if prop_x>=0 & prop_y>=0
replace prop_ucset = 1 ///
	if ///
	(prop_y == 51 & prop_x == 49) | ///
	(prop_y == 50 & prop_x >= 44 & prop_x<=54) | ///
	(prop_y == 49 & prop_x >= 39 & prop_x<=59.5) | ///
	(prop_y == 48 & prop_x >= 37.5 & prop_x <=60.3) | ///
	(prop_y == 47 & prop_x >= 37.5 & prop_x<=60.8) | ///
	(prop_y == 46 & prop_x >= 37.5 & prop_x<=60.8) | ///
	(prop_y == 45 & prop_x >= 37.5 & prop_x<=60.8) | ///
	(prop_y == 44 & prop_x >= 37.5 & prop_x<=60.2) | ///
	(prop_y == 43 & prop_x >= 38 & prop_x<=60.8) | ///
	(prop_y == 42 & prop_x >= 38 & prop_x<=60.8) | ///
	(prop_y == 41 & prop_x >= 38 & prop_x<=60.8) | ///
	(prop_y == 40 & prop_x >= 38 & prop_x<=59.8) | ///
	(prop_y == 39 & prop_x >= 39 & prop_x<=59.3) | ///
	(prop_y == 38 & prop_x >= 39 & prop_x<=59.3) | ///
	(prop_y == 37 & prop_x >= 40 & prop_x<=58.3) | ///
	(prop_y == 36 & prop_x >= 41 & prop_x<=56.8) | ///
	(prop_y == 35 & prop_x >= 42 & prop_x<=55)

